<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <%--常量--%>
    <%@ include file="/common/constHead.jsp"%>
    <%--jQuery--%>
    <%@ include file="/common/jqueryHead.jsp"%>
    <%--jo--%>
    <%@ include file="/common/joHead.jsp"%>
    <%--bootstrap和字体--%>
    <%@ include file="/common/bootstrapHead.jsp"%>
    <%--layer--%>
    <%@ include file="/common/layerHead.jsp"%>
    <%--zTree树--%>
    <%@ include file="/common/zTreeHead.jsp"%>
    <%--公共--%>
    <%@ include file="/common/commonHead.jsp"%>
    <link href="static/css/jquery.treetable.css" rel="stylesheet" type="text/css" />
    <script src="static/js/jquery.treetable.js"></script>
    <title>项目列表</title>
    <script type="text/javascript">
        $(function(){
            loadList();//初始化列表
            createTree("stTree",function(event,treeId,treeNode){
                if(treeNode.stype == "1"){//主类
                    joView.params.condition = "typeOne=" + treeNode.id;
                }else if(treeNode.stype == "2"){//父类
                    joView.params.condition = "typeTwo=" + treeNode.id;
                }else if(treeNode.stype == "3"){//基本类型
                    joView.params.condition = "typeThree=" + treeNode.id;
                }
                joView.select();
            });
        });
        //初始化列表
        function loadList() {
            joView.init({grid:$("#mainList"),PKName:"id"});//初始化页面
        }
        //行处理
        joView.handleItem = function(oItem,iIndex){
            oItem.loadChildren = '<i class="fa fa-plus-square-o" onclick="loadChildrenTable('+oItem.id+', this)" aria-hidden="true"></i>';
        };
        //加载子级table
        function loadChildrenTable(id, obj) {
            //判断当前行元素是否含有table元素
            if($(obj).parent().parent().next().find("table").length > 0){
                //判断table元素是否隐藏
                if(($(obj).parent().parent().next().is(":hidden"))){
                    $(obj).parent().parent().next().show();
                }else {
                    $(obj).parent().parent().next().hide();
                }
            }else {
                jo.postAjax("travel/item/getItemTreeList.action", {"parentId":id}, function(json){
                    if(json && json.code == 0){
                        var _html = '<tr><td colspan="6"><table class="table table-bordered table-hover table-striped table-condensed">';
                        var item = json.data;
                        for(var i = 0 ; i < item.length ; i++){
                            item[i].stype == 1 ? item[i].stypeName = "<span class='bg-primary font-white padding-2'>评价大类</span>" : item[i].stypeName = "<span class='bg-green font-white padding-2'>具体评价小项</span>" ;
                            _html += '<tr>' ;
                            _html += '<td width="50%" align="center"><a onclick="openForm('+item[i].id+')">'+item[i].name+'</a></td>';
                            _html += '<td align="center"><span class="bg-primary font-white padding-2">'+item[i].stypeName+'</span></td>';
                            _html += '<td align="center">'+item[i].gradeMin+'</td>';
                            _html += '<td align="center">'+item[i].gradeMax+'</td>';
                            _html += '</tr>';
                        }
                        $(obj).parent().parent().after(_html);
                    }else {
                        jo.showMsg("暂无子节点数据~~~");
                    }
                });
            }
        }
        //打开表单
        function openForm(id) {
            jo.showWin("page/travel/itemForm.jsp?id="+id+"","800px","500px","编辑");
        }
        //创建树
        function createTree(eleId,clickFunc){
            eleId = jo.getDefVal(eleId, "stTree");
            jo.postAjax("travel/item/getItemList.action", {}, function(json){
                if(json && json.code == 0){
                    /*if(json && json.data && json.data[0] && json.data[0].ID == "ROOT"){
                        json.data[0].open = true;
                    }*/
                    var param = {
                        treeId : eleId
                        ,zNodes : json.data
                        ,item_id : "id"
                        ,item_pid : "parentId"
                        ,item_show : "name"
                    };
                    if(typeof (clickFunc) == "function"){
                        param.onClickFunc = clickFunc;//树节点点击回调
                    }
                    jo.drawZTree(param);
                }else{
                    jo.showMsg("创建树失败!");
                }
            });
        }
    </script>
</head>
<body>

<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
            <%--检索栏--%>
            <form class="form-inline search-bar" id="pageForm">
                <div class="form-group">
                    <label class="control-label">编号：&nbsp;</label>
                    <input type="text" name="id" class="form-control input-sm" value="">
                </div>
                <div class="form-group">
                    <label class="control-label">名称：&nbsp;</label>
                    <input type="text" name="name" class="form-control input-sm" value="">
                </div>
                <button type="button" class="btn btn-primary btn-sm" onclick="joView.select()"> <i class="fa fa-search" aria-hidden="true"></i>&nbsp;查询</button>
            </form>
            <%--/检索栏--%>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
            <%--按钮栏--%>
            <div class="form-group button-bar">
                <button isShow="" type="button" class="btn btn-sm btn-outline btn-primary" onclick="joView.add()">
                    <i class="fa fa-plus" aria-hidden="true"></i>&nbsp;新增
                </button>
                <button type="button" class="btn btn-sm btn-outline btn-danger" onclick="joView.del()">
                    <i class="fa fa-trash-o" aria-hidden="true"></i>&nbsp;删除
                </button>
                <button type="button" class="btn btn-sm btn-outline btn-warning" onclick="window.location.reload()">
                    <i class="fa fa-refresh" aria-hidden="true"></i>&nbsp;刷新
                </button>
            </div>
            <%--/按钮栏--%>
        </div>
    </div>
    <div>
    <div class="row">
        <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
            <%--<div id="stTree" class="ztree">

            </div>--%>
        </div>
        <div class="col-xs-12 col-lg-12 col-md-12 col-sm-12">
            <%--grid--%>
            <div class="table-responsive">
                <table class="table table-bordered table-hover table-striped table-condensed" id="mainList" dataUrl="travel/item/getItemTreeList.action" deleteUrl="travel/item/delete.action" formUrl="page/travel/itemForm.jsp">
                    <%--<col field="id" title="编号" width="15%" align="" event="click"/>--%>
                    <col field="loadChildren" title="" width="5%" align="" />
                    <col field="name" title="评价项" width="50%" align="" event="click"/>
                    <col field="[=parse_type('{stype}',true)]" title="类型" width="15%" align=""/>
                    <%--<col field="parentId" title="父ID" width="15%" align=""/>--%>
                    <col field="gradeMin" title="最低分" width="15%" align=""/>
                    <col field="gradeMax" title="最高分" width="15%" align=""/>
                </table>
            </div>
            <%--/grid--%>

            <%--分页条--%>
            <div class="page-bar" gridId="mainList">

            </div>
            <%--/分页条--%>
        </div>
    </div>
</div>

<script src="<%=URL_STATIC%>static/plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
    jo.formatUI();//格式化jo组件
</script>
</body>
</html>
